package com.kyjszj.common.utils;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;

/**
 * @ClassName ImageUtils
 * @Description TODO
 * @Author luckyboy
 * @Date 2020年07月02日 16:31
 **/
public class ImageUtils {
    public static String url="";
    public static String bing_url="http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1";
    public static String bing="http://cn.bing.com";

    public static String getBingImage(){
        String jsonStr= HttpUtil.get("http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 ");
        JSONArray jsonArray = new JSONObject(jsonStr).getJSONArray("images");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = (JSONObject) jsonArray.get(i);
            if (jsonObject.containsKey("url")) {
                url+=bing+ jsonObject.getStr("url");
            }
        }
        return "".equals(url)?"../img/login-background.jpg":url;
    }
}
